package com.ztx.web.controller.caiwu;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ztx.model.JklsVO;
import com.ztx.model.JklsViewVO;
import com.ztx.pagemodel.SessionInfo;
import com.ztx.pagemodel.easyui.DataGrid;
import com.ztx.pagemodel.easyui.Json;
import com.ztx.pagemodel.easyui.PageHelper;
import com.ztx.service.base.IBaseService;
import com.ztx.service.caiwu.IJklsAuditService;
import com.ztx.utils.Constants;

/**
 * 
 * 交款流水审核
 *
 */

@Controller
@RequestMapping("jklsAuditController")
public class JklsAuditController {

	private static final Logger log = LoggerFactory
			.getLogger(JklsAuditController.class);

	@Resource
	private IJklsAuditService jklsAuditService;

	@Resource
	private IBaseService baseService;

	/**
	 * 跳转到列表页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list() {
		return "caiwu/jkls/jklsAuditList";
	}

	/**
	 * 获取交款流水数据
	 * 
	 * @param ph
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "datagrid", method = RequestMethod.POST)
	@ResponseBody
	public DataGrid<JklsViewVO> jklsDatagird(PageHelper ph, JklsVO params) {
		return jklsAuditService.jklsDatagrid(ph, params);
	}

	/**
	 * 直接审核通过
	 * 
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "auditpass/{id}", method = RequestMethod.POST)
	@ResponseBody
	public Json auditpass(@PathVariable(value = "id") long id,
			HttpServletRequest request) {
		SessionInfo session = (SessionInfo) request.getSession().getAttribute(
				Constants.SESSIONINFO);
		Json json = new Json();
		try {
			jklsAuditService.doAuditPass(id, session);
			json.setMsg("操作成功！");
		} catch (Exception e) {
			json.setSuccess(false);
			json.setMsg(e.getMessage());
		}
		return json;
	}

	/**
	 * 跳转到编辑金额页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "edit/{id}", method = RequestMethod.GET)
	public String editAndPass(@PathVariable(value = "id") long id, Model model) {
		try {
			JklsVO jkls = baseService.selectOne(JklsVO.class.getName()
					+ ".getJklsById", id);
			model.addAttribute("qkinfo", jkls);
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return "caiwu/editandaudit";
	}

	/**
	 * 修改后审核通过
	 * 
	 * @param info
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "updateJkls", method = RequestMethod.POST)
	@ResponseBody
	public Json updateJkls(JklsViewVO jklsViewVO, HttpServletRequest request) {
		SessionInfo session = (SessionInfo) request.getSession().getAttribute(
				Constants.SESSIONINFO);
		Json json = new Json();
		try {
			jklsAuditService.editAndPass(jklsViewVO, session);
		} catch (Exception e) {
			json.setSuccess(false);
			json.setMsg(e.getMessage());
		}
		return json;
	}

}
